#ifndef SENSORMODEL_H
#define SENSORMODEL_H

#include <QAbstractListModel>
#include <QObject>
#include <QModelIndex>
#include "def.h"

enum DataRoles{
    NAME = Qt::UserRole + 1,
    VALID,
    VALUE,
    FORMATE,
    VRESOLUTION,
    UNIT_INDEX,
    UNIT,
    MAXVALUE,
    MINVALUE,
    MAXCUTOFF,
    MINCUTOFF,
    DEVIDE,
};

typedef struct Data{
            QString  name;
            bool    valid;
            FP32  value;
            DATA_FORMATE formate;
            INT08U  vresolution;
            INT16U  unitindex;
            QString  unit;
            FP32  maxvalue;
            FP32  minvalue;
            FP32  maxcutoff;
            FP32  mincutoff;
            QString  devide;
        }DATA;

class SensorModel : public QAbstractListModel
{
    Q_OBJECT



public:
    explicit SensorModel(QObject *parent = nullptr);

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    bool append(DATA data);
    void append(float value,int index);


protected:
    // return the roles mapping to be used by QML
    virtual QHash<int, QByteArray> roleNames() const override;


private:
        QList<Data> dataList;
        QHash<int, QByteArray> m_roleNames;
};

#endif // SENSORMODEL_H
